Add jobs flag to package
authorMatthew Camp <mattscamp@gmail.com>
Wed, 13 Jul 2016 08:38:22 +0000 (15:38 +0700)
committerMatthew Camp <mattscamp@gmail.com>
Wed, 13 Jul 2016 08:38:22 +0000 (15:38 +0700)
src/bin/package.rs
src/bin/publish.rs
src/cargo/ops/cargo_package.rs
src/cargo/ops/registry.rs

index dda718373dbc71bf66fc64942b201877d9b011fb..4a45408540919f209f33003cf3811d8ab687918f 100644 (file)
@@ -13,6 +13,7 @@ pub struct Options {
     flag_no_metadata: bool,
     flag_list: bool,
     flag_allow_dirty: bool,
+    flag_jobs: Option<u32>,
 }
 
 pub const USAGE: &'static str = "
@@ -28,10 +29,10 @@ Options:
     --no-metadata           Ignore warnings about a lack of human-usable metadata
     --allow-dirty           Allow dirty working directories to be packaged
     --manifest-path PATH    Path to the manifest to compile
+    -j N, --jobs N          Number of parallel jobs, defaults to # of CPUs
     -v, --verbose ...       Use verbose output
     -q, --quiet             No output printed to stdout
     --color WHEN            Coloring: auto, always, never
-
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
@@ -46,6 +47,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         list: options.flag_list,
         check_metadata: !options.flag_no_metadata,
         allow_dirty: options.flag_allow_dirty,
+        jobs: options.flag_jobs,
     }));
     Ok(None)
 }
index 1300668688368f8c864965b4b68a5ef0ee75b81a..97aa2e1376458e96f840a2909cfe3cc7b0739114 100644 (file)
@@ -13,6 +13,7 @@ pub struct Options {
     flag_color: Option<String>,
     flag_no_verify: bool,
     flag_allow_dirty: bool,
+    flag_jobs: Option<u32>,
 }
 
 pub const USAGE: &'static str = "
@@ -28,6 +29,7 @@ Options:
     --no-verify              Don't verify package tarball before publish
     --allow-dirty            Allow publishing with a dirty source directory
     --manifest-path PATH     Path to the manifest of the package to publish
+    -j N, --jobs N           Number of parallel jobs, defaults to # of CPUs
     -v, --verbose ...        Use verbose output
     -q, --quiet              No output printed to stdout
     --color WHEN             Coloring: auto, always, never
@@ -44,6 +46,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         flag_manifest_path,
         flag_no_verify: no_verify,
         flag_allow_dirty: allow_dirty,
+        flag_jobs: jobs,
         ..
     } = options;
 
@@ -55,6 +58,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         index: host,
         verify: !no_verify,
         allow_dirty: allow_dirty,
+        jobs: jobs,
     }));
     Ok(None)
 }
index 461068fb407777b5e0da4aefd868db3e378501e1..c22f44cd6ee0bd208f8a6fa72e53fe2657160b1c 100644 (file)
@@ -19,6 +19,7 @@ pub struct PackageOpts<'cfg> {
     pub check_metadata: bool,
     pub allow_dirty: bool,
     pub verify: bool,
+    pub jobs: Option<u32>,
 }
 
 pub fn package(ws: &Workspace,
@@ -68,7 +69,7 @@ pub fn package(ws: &Workspace,
     }));
     if opts.verify {
         try!(dst.seek(SeekFrom::Start(0)));
-        try!(run_verify(ws, dst.file()).chain_error(|| {
+        try!(run_verify(ws, dst.file(), opts).chain_error(|| {
             human("failed to verify package tarball")
         }))
     }
@@ -228,7 +229,7 @@ fn tar(ws: &Workspace,
     Ok(())
 }
 
-fn run_verify(ws: &Workspace, tar: &File) -> CargoResult<()> {
+fn run_verify(ws: &Workspace, tar: &File, opts: &PackageOpts) -> CargoResult<()> {
     let config = ws.config();
     let pkg = try!(ws.current());
 
@@ -268,7 +269,7 @@ fn run_verify(ws: &Workspace, tar: &File) -> CargoResult<()> {
     let ws = Workspace::one(new_pkg, config);
     try!(ops::compile_ws(&ws, None, &ops::CompileOptions {
         config: config,
-        jobs: None,
+        jobs: opts.jobs,
         target: None,
         features: &[],
         no_default_features: false,
index a076f01d4d1fd5ccc970e5d28f3982bd63b5a859..cda3d9abec9a6b1ea62c50d2ed0bd6d22ea13fe9 100644 (file)
@@ -35,6 +35,7 @@ pub struct PublishOpts<'cfg> {
     pub index: Option<String>,
     pub verify: bool,
     pub allow_dirty: bool,
+    pub jobs: Option<u32>,
 }
 
 pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> {
@@ -58,6 +59,7 @@ pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> {
         list: false,
         check_metadata: true,
         allow_dirty: opts.allow_dirty,
+        jobs: opts.jobs,
     })).unwrap();
 
     // Upload said tarball to the specified destination